package com.example.dangerouscargodriver.ui.activity;

import android.content.Intent;
import android.util.Log;

import androidx.annotation.Nullable;

import com.example.dangerouscargodriver.controller.AuthController;

public abstract class AuthCheckActivity extends HttpRequestActivity {

    private static final String TAG = "AuthCheckActivity";
    private static final int ACTION_LOGIN = 0;

    protected abstract void onLogIn();

    protected abstract void onLogOut();

    public boolean checkAuth(){
        return AuthController.Instance().checkLogin();
    }

    public void gotoLogInActivity(){
        Intent intent = new Intent(AuthCheckActivity.this, LogInActivity.class);
        startActivityForResult(intent, ACTION_LOGIN);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //此处可以根据两个Code进行判断，本页面和结果页面跳过来的值
        if (requestCode == ACTION_LOGIN) {
            if(AuthController.Instance().checkLogin()){
                onLogIn();
            }
            else{
                onLogOut();
            }
        }
        else {
            /**/
        }
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }
}
